﻿Public Class JenisDokumen
    Inherits System.Web.UI.Page

    Dim komen As Boolean
    Dim kueri As String


    Dim koneksidataakses1 As New KoneksiDataAkses
    Sub bersih()
        textbox1.Text = ""
        textbox2.Text = ""
        test_grid.SelectedIndex = -1
        DropDownList1.SelectedValue = 0
    End Sub


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        test_grid.DataBind()
        tableboy.Visible = False
    End Sub

    Protected Sub test_grid_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles test_grid.RowCommand
        If e.CommandName = "btnCopy" Then
            bersih()
            textbox1.Text = test_grid.Rows(e.CommandArgument.ToString).Cells(1).Text
            textbox2.Text = test_grid.Rows(e.CommandArgument.ToString).Cells(2).Text
            If test_grid.Rows(e.CommandArgument.ToString).Cells(3).Text = "Aktif" Then
                DropDownList1.SelectedValue = 0
            ElseIf test_grid.Rows(e.CommandArgument.ToString).Cells(3).Text = "Pasif" Then
                DropDownList1.SelectedValue = 1
            End If
            System.Web.HttpContext.Current.Session("status_action") = True
            tableboy.Visible = True

            'ElseIf e.CommandName = "btnEdit" Then
            '    'Label1.Text = test_grid.Rows(e.CommandArgument.ToString).Cells(3).Text
            '    textbox1.Text = test_grid.Rows(e.CommandArgument.ToString).Cells(1).Text
            '    textbox2.Text = test_grid.Rows(e.CommandArgument.ToString).Cells(2).Text
            '    System.Web.HttpContext.Current.Session("status_action") = False
        End If
    End Sub

    Protected Sub Button4_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button4.Click
        System.Web.HttpContext.Current.Session("status_action") = True
        tableboy.Visible = True
        bersih()
    End Sub

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click

        If Session("status_action") = True Then
            koneksidataakses1.cekDuplikat("TB_MST_JENIS_DOK", "jenis_dok", textbox1.Text)
            If koneksidataakses1.ds.Tables(0).Rows.Count = 0 Then
                kueri = "insert into TB_MST_JENIS_DOK (jenis_dok,deskripsi,is_active,tgl_update) values ('" + textbox1.Text + "','" + textbox2.Text + "', " + DropDownList1.SelectedValue.ToString + ", current_timestamp)"
                koneksidataakses1.EksekusiNonQuery(kueri)
                test_grid.DataBind()
                bersih()
                tableboy.Visible = False
            Else
                Response.Write("ada data yang sama")
            End If
        ElseIf Session("status_action") = False Then
            kueri = "update TB_MST_JENIS_DOK set jenis_dok='" + textbox1.Text + "', deskripsi='" + textbox2.Text + "', is_active= " + DropDownList1.SelectedValue.ToString + ",tgl_update = current_timestamp where id_jenis_dok= " + test_grid.SelectedRow.Cells(0).Text + " "
            koneksidataakses1.EksekusiNonQuery(kueri)
            test_grid.DataBind()
            bersih()
            tableboy.Visible = False
        End If
    End Sub


    Protected Sub test_grid_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles test_grid.SelectedIndexChanged
        textbox1.Text = test_grid.SelectedRow.Cells(1).Text
        textbox2.Text = test_grid.SelectedRow.Cells(2).Text
        If test_grid.SelectedRow.Cells(3).Text = "Aktif" Then
            DropDownList1.SelectedValue = 0
        ElseIf test_grid.SelectedRow.Cells(3).Text = "Pasif" Then
            DropDownList1.SelectedValue = 1
        End If
        System.Web.HttpContext.Current.Session("status_action") = False
        tableboy.Visible = True
    End Sub

    Protected Sub test_grid_PageIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles test_grid.PageIndexChanged
        bersih()
    End Sub

    Protected Sub Button3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button3.Click
        bersih()
        tableboy.Visible = False
    End Sub

    Protected Sub test_grid_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles test_grid.PageIndexChanging
        test_grid.PageIndex = e.NewPageIndex
    End Sub


End Class